<?php
class Cate_model extends CI_Model 
{
	var $table = "category";
	
	/**
	*获取所有分类
	*
	*/
	function getAll()
	{
		return $this->db
					->order_by("px")
					->get($this->table)
					->result_array();
	}
	
	/**
	**获取一条分类
	**
	**/
	function getOne($id)
	{
		return $this->db->from($this->table)
				 ->where("id", $id)
				 ->get()
				 ->row_array();
	}
	
	/**
	**添加分类
	**
	**/
	function add()
	{
		$data = array(
				'cate_name' =>  $this->input->post('cate_name'),
				'px' =>  $this->input->post('px'),
		);
		$this->db->insert($this->table, $data);
	}
	
	/**
	**修改分类
	**
	**/
	function edit()
	{
		$data = array(
				'cate_name' =>  $this->input->post('cate_name'),
				'px' =>  $this->input->post('px'),
		);
		$id = $this->input->post('id');
		$this->db->where('id', $id)->update($this->table, $data);
	}
	
	/**
	**删除分类
	**
	**/
	function del()
	{
		$id = $this->uri->segment(4);
		$this->db->where('id',$id)->delete($this->table);
	}
	
	
}
?>